package com.aso114.project.mvp.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.base.BaseSimpleActivity;
import com.aso114.project.mvp.LoginSP;
import com.aso114.project.util.SystemBarHelper;
import com.aso114.project.util.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 报考信息界面 开始学习
 */
public class ExamAddressActivity extends BaseSimpleActivity {
    @BindView(R.id.layout_title_bar_back_iv)
    ImageView layoutTitleBarBackIv;
    @BindView(R.id.layout_title_bar_title_tv)
    TextView layoutTitleBarTitleTv;
    @BindView(R.id.layout_title_bar_right_iv)
    ImageView layoutTitleBarRightIv;
    @BindView(R.id.choice)
    RelativeLayout choice;
    @BindView(R.id.start)
    TextView start;
    Intent intent;
    public static ExamAddressActivity instance; // 声明一下
    @BindView(R.id.title_top_ly)
    RelativeLayout titleTopLy;
    @BindView(R.id.address_text)
    TextView addressText;

    @Override
    protected int getResouseId() {
        return R.layout.activity_examaddress;
    }

    @Override
    protected void initView() {
        SystemBarHelper.immersiveStatusBar(this);
        SystemBarHelper.setHeightAndPadding(this, titleTopLy);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            SystemBarHelper.immersiveStatusBar(this, 0);
            SystemBarHelper.setStatusBarDarkMode(this);
        }
        layoutTitleBarTitleTv.setText("报考信息");
        instance = this;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (LoginSP.getInstance().getCityname().equals("")) {
            addressText.setText("请选择");
            addressText.setTextColor(getResources().getColor(R.color.a999999));
        } else {
            addressText.setTextColor(getResources().getColor(R.color.a333333));

            if (LoginSP.getInstance().getCityname().equals("国考")) {
                addressText.setText("国考");
            } else {
                String city_name = LoginSP.getInstance().getCityname().replace("考", "");
                addressText.setText(city_name);
            }

        }
    }

    @Override
    protected void getBroadcast(Context context, Intent intent) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.layout_title_bar_back_iv, R.id.layout_title_bar_title_tv, R.id.choice, R.id.start})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.layout_title_bar_back_iv:

                if (LoginSP.getInstance().getFirst().equals("")) {
                    //表示第一次登陆 必须选择考区
                    ToastUtils.showToast(ExamAddressActivity.this, "请选择考区");

                } else {
                    finish();
                }


//                finish();
                break;
            case R.id.choice:
                intent = new Intent(ExamAddressActivity.this, ChoiceExamActivity.class);
                startActivity(intent);
                break;
            case R.id.start:

//                String cityid = "3";
                if (ChoiceExamActivity.cityid.equals("")) {

                    ToastUtils.showToast(ExamAddressActivity.this, "请选择考区");

                    return;
                }

                LoginSP.getInstance().setFirst("1");//表示不是第一次运行
                intent = new Intent(ExamAddressActivity.this, MainActivity.class);
                startActivity(intent);
                break;
            case R.id.layout_title_bar_title_tv:
                break;
        }
    }


    // 捕获返回键的方法
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {


            ToastUtils.showToast(ExamAddressActivity.this, "请选择考区");

            return false;

        } else {

            return super.onKeyDown(keyCode, event);

        }

    }

}
